package state;

/**
 * Remarks:
 * Class name :Stop
 * Date :2023/2/14 16:35
 * Author:杨俊源
 */
public class Stop implements Runnable{

    private boolean flag = true;

    @Override
    public void run() {
        int i = 0;
        while (flag){
            System.out.println("run ... Thread " + i++);
        }
    }

    public void stop(){
        this.flag = false;
    }

    public static void main(String[] args) {
        Stop stop = new Stop();
        new Thread(stop).start();
        for (int i = 0; i < 1000; i++) {
            System.out.println("main :" + i);
            if (i == 900){
                stop.stop();
                System.out.println("线程停止了");
            }
        }
    }
}
